home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / rallyx.c < prev    next >
C/C++ Source or Header  |  2000-05-21  |  20KB  |  832 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char *rallyx_videoram2,*rallyx_colorram2;
  15. unsigned char *rallyx_radarx,*rallyx_radary,*rallyx_radarattr;
  16. size_t rallyx_radarram_size;
  17. unsigned char *rallyx_scrollx,*rallyx_scrolly;
  18. static unsigned char *dirtybuffer2;    /* keep track of modified portions of the screen */
  19.                                             /* to speed up video refresh */
  20. static struct osd_bitmap *tmpbitmap1;
  21. static int flipscreen;
  22.  
  23.  
  24.  
  25. static struct rectangle spritevisiblearea =
  26. {
  27.     0*8, 28*8-1,
  28.     0*8, 28*8-1
  29. };
  30.  
  31. static struct rectangle spritevisibleareaflip =
  32. {
  33.     8*8, 36*8-1,
  34.     0*8, 28*8-1
  35. };
  36.  
  37. static struct rectangle radarvisiblearea =
  38. {
  39.     28*8, 36*8-1,
  40.     0*8, 28*8-1
  41. };
  42.  
  43. static struct rectangle radarvisibleareaflip =
  44. {
  45.     0*8, 8*8-1,
  46.     0*8, 28*8-1
  47. };
  48.  
  49.  
  50.  
  51. /***************************************************************************
  52.  
  53.   Convert the color PROMs into a more useable format.
  54.  
  55.   Rally X has one 32x8 palette PROM and one 256x4 color lookup table PROM.
  56.   The palette PROM is connected to the RGB output this way:
  57.  
  58.   bit 7 -- 220 ohm resistor  -- BLUE
  59.         -- 470 ohm resistor  -- BLUE
  60.         -- 220 ohm resistor  -- GREEN
  61.         -- 470 ohm resistor  -- GREEN
  62.         -- 1  kohm resistor  -- GREEN
  63.         -- 220 ohm resistor  -- RED
  64.         -- 470 ohm resistor  -- RED
  65.   bit 0 -- 1  kohm resistor  -- RED
  66.  
  67.   In Rally-X there is a 1 kohm pull-down on B only, in Locomotion the
  68.   1 kohm pull-down is an all three RGB outputs.
  69.  
  70. ***************************************************************************/
  71. void rallyx_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  72. {
  73.     int i;
  74.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  75.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  76.  
  77.  
  78.     for (i = 0;i < Machine->drv->total_colors;i++)
  79.     {
  80.         int bit0,bit1,bit2;
  81.  
  82.  
  83.         /* red component */
  84.         bit0 = (*color_prom >> 0) & 0x01;
  85.         bit1 = (*color_prom >> 1) & 0x01;
  86.         bit2 = (*color_prom >> 2) & 0x01;
  87.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  88.         /* green component */
  89.         bit0 = (*color_prom >> 3) & 0x01;
  90.         bit1 = (*color_prom >> 4) & 0x01;
  91.         bit2 = (*color_prom >> 5) & 0x01;
  92.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  93.         /* blue component */
  94.         bit0 = 0;
  95.         bit1 = (*color_prom >> 6) & 0x01;
  96.         bit2 = (*color_prom >> 7) & 0x01;
  97.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  98.  
  99.         color_prom++;
  100.     }
  101.  
  102.     /* color_prom now points to the beginning of the lookup table */
  103.  
  104.     /* character lookup table */
  105.     /* sprites use the same color lookup table as characters */
  106.     /* characters use colors 0-15 */
  107.     for (i = 0;i < TOTAL_COLORS(0);i++)
  108.         COLOR(0,i) = *(color_prom++) & 0x0f;
  109.  
  110.     /* radar dots lookup table */
  111.     /* they use colors 16-19 */
  112.     for (i = 0;i < 4;i++)
  113.         COLOR(2,i) = 16 + i;
  114. }
  115.  
  116. void locomotn_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  117. {
  118.     int i;
  119.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  120.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  121.  
  122.  
  123.     for (i = 0;i < Machine->drv->total_colors;i++)
  124.     {
  125.         int bit0,bit1,bit2;
  126.  
  127.  
  128.         /* red component */
  129.         bit0 = (*color_prom >> 0) & 0x01;
  130.         bit1 = (*color_prom >> 1) & 0x01;
  131.         bit2 = (*color_prom >> 2) & 0x01;
  132.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  133.         /* green component */
  134.         bit0 = (*color_prom >> 3) & 0x01;
  135.         bit1 = (*color_prom >> 4) & 0x01;
  136.         bit2 = (*color_prom >> 5) & 0x01;
  137.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  138.         /* blue component */
  139.         bit0 = (*color_prom >> 6) & 0x01;
  140.         bit1 = (*color_prom >> 7) & 0x01;
  141.         *(palette++) = 0x50 * bit0 + 0xab * bit1;
  142.  
  143.         color_prom++;
  144.     }
  145.  
  146.     /* color_prom now points to the beginning of the lookup table */
  147.  
  148.     /* character lookup table */
  149.     /* sprites use the same color lookup table as characters */
  150.     /* characters use colors 0-15 */
  151.     for (i = 0;i < TOTAL_COLORS(0);i++)
  152.         COLOR(0,i) = *(color_prom++) & 0x0f;
  153.  
  154.     /* radar dots lookup table */
  155.     /* they use colors 16-19 */
  156.     for (i = 0;i < 4;i++)
  157.         COLOR(2,i) = 16 + i;
  158. }
  159.  
  160.  
  161. /***************************************************************************
  162.  
  163.   Start the video hardware emulation.
  164.  
  165. ***************************************************************************/
  166. int rallyx_vh_start(void)
  167. {
  168.     if (generic_vh_start() != 0)
  169.         return 1;
  170.  
  171.     if ((dirtybuffer2 = malloc(videoram_size)) == 0)
  172.         return 1;
  173.     memset(dirtybuffer2,1,videoram_size);
  174.  
  175.     if ((tmpbitmap1 = osd_create_bitmap(32*8,32*8)) == 0)
  176.     {
  177.         free(dirtybuffer2);
  178.         generic_vh_stop();
  179.         return 1;
  180.     }
  181.  
  182.     return 0;
  183. }
  184.  
  185.  
  186.  
  187. /***************************************************************************
  188.  
  189.   Stop the video hardware emulation.
  190.  
  191. ***************************************************************************/
  192. void rallyx_vh_stop(void)
  193. {
  194.     osd_free_bitmap(tmpbitmap1);
  195.     free(dirtybuffer2);
  196.     generic_vh_stop();
  197. }
  198.  
  199.  
  200.  
  201. WRITE_HANDLER( rallyx_videoram2_w )
  202. {
  203.     if (rallyx_videoram2[offset] != data)
  204.     {
  205.         dirtybuffer2[offset] = 1;
  206.  
  207.         rallyx_videoram2[offset] = data;
  208.     }
  209. }
  210.  
  211.  
  212. WRITE_HANDLER( rallyx_colorram2_w )
  213. {
  214.     if (rallyx_colorram2[offset] != data)
  215.     {
  216.         dirtybuffer2[offset] = 1;
  217.  
  218.         rallyx_colorram2[offset] = data;
  219.     }
  220. }
  221.  
  222.  
  223.  
  224. WRITE_HANDLER( rallyx_flipscreen_w )
  225. {
  226.     if (flipscreen != (data & 1))
  227.     {
  228.         flipscreen = data & 1;
  229.         memset(dirtybuffer,1,videoram_size);
  230.         memset(dirtybuffer2,1,videoram_size);
  231.     }
  232. }
  233.  
  234.  
  235.  
  236. /***************************************************************************
  237.  
  238.   Draw the game screen in the given osd_bitmap.
  239.   Do NOT call osd_update_display() from this function, it will be called by
  240.   the main emulation engine.
  241.  
  242. ***************************************************************************/
  243.  
  244. void rallyx_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  245. {
  246.     int offs,sx,sy;
  247.     int scrollx,scrolly;
  248. const int displacement = 1;
  249.  
  250.  
  251.     if (flipscreen)
  252.     {
  253.         scrollx = (*rallyx_scrollx - displacement) + 32;
  254.         scrolly = (*rallyx_scrolly + 16) - 32;
  255.     }
  256.     else
  257.     {
  258.         scrollx = -(*rallyx_scrollx - 3*displacement);
  259.         scrolly = -(*rallyx_scrolly + 16);
  260.     }
  261.  
  262.  
  263.     /* draw the below sprite priority characters */
  264.     for (offs = videoram_size - 1;offs >= 0;offs--)
  265.     {
  266.         if (rallyx_colorram2[offs] & 0x20)  continue;
  267.  
  268.         if (dirtybuffer2[offs])
  269.         {
  270.             int flipx,flipy;
  271.  
  272.  
  273.             dirtybuffer2[offs] = 0;
  274.  
  275.             sx = offs % 32;
  276.             sy = offs / 32;
  277.             flipx = ~rallyx_colorram2[offs] & 0x40;
  278.             flipy = rallyx_colorram2[offs] & 0x80;
  279.             if (flipscreen)
  280.             {
  281.                 sx = 31 - sx;
  282.                 sy = 31 - sy;
  283.                 flipx = !flipx;
  284.                 flipy = !flipy;
  285.             }
  286.  
  287.             drawgfx(tmpbitmap1,Machine->gfx[0],
  288.                     rallyx_videoram2[offs],
  289.                     rallyx_colorram2[offs] & 0x3f,
  290.                     flipx,flipy,
  291.                     8*sx,8*sy,
  292.                     0,TRANSPARENCY_NONE,0);
  293.         }
  294.     }
  295.  
  296.     /* update radar */
  297.     for (offs = videoram_size - 1;offs >= 0;offs--)
  298.     {
  299.         if (dirtybuffer[offs])
  300.         {
  301.             int flipx,flipy;
  302.  
  303.  
  304.             dirtybuffer[offs] = 0;
  305.  
  306.             sx = (offs % 32) ^ 4;
  307.             sy = offs / 32 - 2;
  308.             flipx = ~colorram[offs] & 0x40;
  309.             flipy = colorram[offs] & 0x80;
  310.             if (flipscreen)
  311.             {
  312.                 sx = 7 - sx;
  313.                 sy = 27 - sy;
  314.                 flipx = !flipx;
  315.                 flipy = !flipy;
  316.             }
  317.  
  318.             drawgfx(tmpbitmap,Machine->gfx[0],
  319.                     videoram[offs],
  320.                     colorram[offs] & 0x3f,
  321.                     flipx,flipy,
  322.                     8*sx,8*sy,
  323.                     &radarvisibleareaflip,TRANSPARENCY_NONE,0);
  324.         }
  325.     }
  326.  
  327.  
  328.     /* copy the temporary bitmap to the screen */
  329.     copyscrollbitmap(bitmap,tmpbitmap1,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  330.  
  331.  
  332.     /* draw the sprites */
  333.     for (offs = 0;offs < spriteram_size;offs += 2)
  334.     {
  335.         sx = spriteram[offs + 1] + ((spriteram_2[offs + 1] & 0x80) << 1) - displacement;
  336.         sy = 225 - spriteram_2[offs] - displacement;
  337.  
  338.         drawgfx(bitmap,Machine->gfx[1],
  339.                 (spriteram[offs] & 0xfc) >> 2,
  340.                 spriteram_2[offs + 1] & 0x3f,
  341.                 spriteram[offs] & 1,spriteram[offs] & 2,
  342.                 sx,sy,
  343.                 flipscreen ? &spritevisibleareaflip : &spritevisiblearea,TRANSPARENCY_COLOR,0);
  344.     }
  345.  
  346.  
  347.     /* draw the above sprite priority characters */
  348.     for (offs = videoram_size - 1;offs >= 0;offs--)
  349.     {
  350.         int flipx,flipy;
  351.  
  352.  
  353.         if (!(rallyx_colorram2[offs] & 0x20))  continue;
  354.  
  355.         sx = offs % 32;
  356.         sy = offs / 32;
  357.         flipx = ~rallyx_colorram2[offs] & 0x40;
  358.         flipy = rallyx_colorram2[offs] & 0x80;
  359.         if (flipscreen)
  360.         {
  361.             sx = 31 - sx;
  362.             sy = 31 - sy;
  363.             flipx = !flipx;
  364.             flipy = !flipy;
  365.         }
  366.  
  367.         drawgfx(bitmap,Machine->gfx[0],
  368.                 rallyx_videoram2[offs],
  369.                 rallyx_colorram2[offs] & 0x3f,
  370.                 flipx,flipy,
  371.                 (8*sx + scrollx) & 0xff,(8*sy + scrolly) & 0xff,
  372.                 0,TRANSPARENCY_NONE,0);
  373.         drawgfx(bitmap,Machine->gfx[0],
  374.                 rallyx_videoram2[offs],
  375.                 rallyx_colorram2[offs] & 0x3f,
  376.                 flipx,flipy,
  377.                 ((8*sx + scrollx) & 0xff) - 256,(8*sy + scrolly) & 0xff,
  378.                 0,TRANSPARENCY_NONE,0);
  379.     }
  380.  
  381.  
  382.     /* radar */
  383.     if (flipscreen)
  384.         copybitmap(bitmap,tmpbitmap,0,0,0,0,&radarvisibleareaflip,TRANSPARENCY_NONE,0);
  385.     else
  386.         copybitmap(bitmap,tmpbitmap,0,0,28*8,0,&radarvisiblearea,TRANSPARENCY_NONE,0);
  387.  
  388.  
  389.     /* draw the cars on the radar */
  390.     for (offs = 0; offs < rallyx_radarram_size;offs++)
  391.     {
  392.         int x,y;
  393.  
  394.         x = rallyx_radarx[offs] + ((~rallyx_radarattr[offs] & 0x01) << 8) - 2;
  395.         y = 235 - rallyx_radary[offs];
  396.         if (flipscreen)
  397.         {
  398.             x -= 1;
  399.             y += 2;
  400.         }
  401.  
  402.         drawgfx(bitmap,Machine->gfx[2],
  403.                 ((rallyx_radarattr[offs] & 0x0e) >> 1) ^ 0x07,
  404.                 0,
  405.                 flipscreen,flipscreen,
  406.                 x,y,
  407.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,3);
  408.     }
  409. }
  410.  
  411.  
  412.  
  413. void jungler_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  414. {
  415.     int offs,sx,sy;
  416.     int scrollx,scrolly;
  417. const int displacement = 0;
  418.  
  419.  
  420.     if (flipscreen)
  421.     {
  422.         scrollx = (*rallyx_scrollx - displacement) + 32;
  423.         scrolly = (*rallyx_scrolly + 16) - 32;
  424.     }
  425.     else
  426.     {
  427.         scrollx = -(*rallyx_scrollx - 3*displacement);
  428.         scrolly = -(*rallyx_scrolly + 16);
  429.     }
  430.  
  431.  
  432.     for (offs = videoram_size - 1;offs >= 0;offs--)
  433.     {
  434.         if (dirtybuffer2[offs])
  435.         {
  436.             int flipx,flipy;
  437.  
  438.  
  439.             dirtybuffer2[offs] = 0;
  440.  
  441.             sx = offs % 32;
  442.             sy = offs / 32;
  443.             flipx = ~rallyx_colorram2[offs] & 0x40;
  444.             flipy = rallyx_colorram2[offs] & 0x80;
  445.             if (flipscreen)
  446.             {
  447.                 sx = 31 - sx;
  448.                 sy = 31 - sy;
  449.                 flipx = !flipx;
  450.                 flipy = !flipy;
  451.             }
  452.  
  453.             drawgfx(tmpbitmap1,Machine->gfx[0],
  454.                     rallyx_videoram2[offs],
  455.                     rallyx_colorram2[offs] & 0x3f,
  456.                     flipx,flipy,
  457.                     8*sx,8*sy,
  458.                     0,TRANSPARENCY_NONE,0);
  459.         }
  460.     }
  461.  
  462.     /* update radar */
  463.     for (offs = videoram_size - 1;offs >= 0;offs--)
  464.     {
  465.         if (dirtybuffer[offs])
  466.         {
  467.             int flipx,flipy;
  468.  
  469.  
  470.             dirtybuffer[offs] = 0;
  471.  
  472.             sx = (offs % 32) ^ 4;
  473.             sy = offs / 32 - 2;
  474.             flipx = ~colorram[offs] & 0x40;
  475.             flipy = colorram[offs] & 0x80;
  476.             if (flipscreen)
  477.             {
  478.                 sx = 7 - sx;
  479.                 sy = 27 - sy;
  480.                 flipx = !flipx;
  481.                 flipy = !flipy;
  482.             }
  483.  
  484.             drawgfx(tmpbitmap,Machine->gfx[0],
  485.                     videoram[offs],
  486.                     colorram[offs] & 0x3f,
  487.                     flipx,flipy,
  488.                     8*sx,8*sy,
  489.                     &radarvisibleareaflip,TRANSPARENCY_NONE,0);
  490.         }
  491.     }
  492.  
  493.  
  494.     /* copy the temporary bitmap to the screen */
  495.     copyscrollbitmap(bitmap,tmpbitmap1,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  496.  
  497.  
  498.     /* draw the sprites */
  499.     for (offs = 0;offs < spriteram_size;offs += 2)
  500.     {
  501.         sx = spriteram[offs + 1] + ((spriteram_2[offs + 1] & 0x80) << 1) - displacement;
  502.         sy = 225 - spriteram_2[offs] - displacement;
  503.  
  504.         drawgfx(bitmap,Machine->gfx[1],
  505.                 (spriteram[offs] & 0xfc) >> 2,
  506.                 spriteram_2[offs + 1] & 0x3f,
  507.                 spriteram[offs] & 1,spriteram[offs] & 2,
  508.                 sx,sy,
  509.                 flipscreen ? &spritevisibleareaflip : &spritevisiblearea,TRANSPARENCY_COLOR,0);
  510.     }
  511.  
  512.  
  513.     /* radar */
  514.     if (flipscreen)
  515.         copybitmap(bitmap,tmpbitmap,0,0,0,0,&radarvisibleareaflip,TRANSPARENCY_NONE,0);
  516.     else
  517.         copybitmap(bitmap,tmpbitmap,0,0,28*8,0,&radarvisiblearea,TRANSPARENCY_NONE,0);
  518.  
  519.  
  520.     /* draw the cars on the radar */
  521.     for (offs = 0; offs < rallyx_radarram_size;offs++)
  522.     {
  523.         int x,y;
  524.  
  525.         x = rallyx_radarx[offs] + ((~rallyx_radarattr[offs] & 0x08) << 5);
  526.         y = 237 - rallyx_radary[offs];
  527.  
  528.         drawgfx(bitmap,Machine->gfx[2],
  529.                 (rallyx_radarattr[offs] & 0x07) ^ 0x07,
  530.                 0,
  531.                 flipscreen,flipscreen,
  532.                 x,y,
  533.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  534.     }
  535. }
  536.  
  537.  
  538.  
  539. void locomotn_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  540. {
  541.     int offs,sx,sy;
  542.  
  543.  
  544.     /* for every character in the Video RAM, check if it has been modified */
  545.     /* since last time and update it accordingly. */
  546.     for (offs = videoram_size - 1;offs >= 0;offs--)
  547.     {
  548.         if (dirtybuffer2[offs])
  549.         {
  550.             int flipx,flipy;
  551.  
  552.  
  553.             dirtybuffer2[offs] = 0;
  554.  
  555.             sx = offs % 32;
  556.             sy = offs / 32;
  557.             /* not a mistake, one bit selects both  flips */
  558.             flipx = rallyx_colorram2[offs] & 0x80;
  559.             flipy = rallyx_colorram2[offs] & 0x80;
  560.             if (flipscreen)
  561.             {
  562.                 sx = 31 - sx;
  563.                 sy = 31 - sy;
  564.                 flipx = !flipx;
  565.                 flipy = !flipy;
  566.             }
  567.  
  568.             drawgfx(tmpbitmap1,Machine->gfx[0],
  569.                     (rallyx_videoram2[offs]&0x7f) + 2*(rallyx_colorram2[offs]&0x40) + 2*(rallyx_videoram2[offs]&0x80),
  570.                     rallyx_colorram2[offs] & 0x3f,
  571.                     flipx,flipy,
  572.                     8*sx,8*sy,
  573.                     0,TRANSPARENCY_NONE,0);
  574.         }
  575.     }
  576.  
  577.     /* update radar */
  578.     for (offs = videoram_size - 1;offs >= 0;offs--)
  579.     {
  580.         if (dirtybuffer[offs])
  581.         {
  582.             int flipx,flipy;
  583.  
  584.  
  585.             dirtybuffer[offs] = 0;
  586.  
  587.             sx = (offs % 32) ^ 4;
  588.             sy = offs / 32 - 2;
  589.             /* not a mistake, one bit selects both  flips */
  590.             flipx = colorram[offs] & 0x80;
  591.             flipy = colorram[offs] & 0x80;
  592.             if (flipscreen)
  593.             {
  594.                 sx = 7 - sx;
  595.                 sy = 27 - sy;
  596.                 flipx = !flipx;
  597.                 flipy = !flipy;
  598.             }
  599.  
  600.             drawgfx(tmpbitmap,Machine->gfx[0],
  601.                     (videoram[offs]&0x7f) + 2*(colorram[offs]&0x40) + 2*(videoram[offs]&0x80),
  602.                     colorram[offs] & 0x3f,
  603.                     flipx,flipy,
  604.                     8*sx,8*sy,
  605.                     &radarvisibleareaflip,TRANSPARENCY_NONE,0);
  606.         }
  607.     }
  608.  
  609.  
  610.     /* copy the temporary bitmap to the screen */
  611.     {
  612.         int scrollx,scrolly;
  613.  
  614.  
  615.         if (flipscreen)
  616.         {
  617.             scrollx = (*rallyx_scrollx) + 32;
  618.             scrolly = (*rallyx_scrolly + 16) - 32;
  619.         }
  620.         else
  621.         {
  622.             scrollx = -(*rallyx_scrollx);
  623.             scrolly = -(*rallyx_scrolly + 16);
  624.         }
  625.  
  626.         copyscrollbitmap(bitmap,tmpbitmap1,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  627.     }
  628.  
  629.  
  630.     /* radar */
  631.     if (flipscreen)
  632.         copybitmap(bitmap,tmpbitmap,0,0,0,0,&radarvisibleareaflip,TRANSPARENCY_NONE,0);
  633.     else
  634.         copybitmap(bitmap,tmpbitmap,0,0,28*8,0,&radarvisiblearea,TRANSPARENCY_NONE,0);
  635.  
  636.  
  637.     /* draw the sprites */
  638.     for (offs = 0;offs < spriteram_size;offs += 2)
  639.     {
  640.         sx = spriteram[offs + 1] - 1;
  641.         sy = 224 - spriteram_2[offs];
  642. if (flipscreen) sx += 32;
  643.  
  644.         drawgfx(bitmap,Machine->gfx[1],
  645.                 ((spriteram[offs] & 0x7c) >> 2) + 0x20*(spriteram[offs] & 0x01) + ((spriteram[offs] & 0x80) >> 1),
  646.                 spriteram_2[offs + 1] & 0x3f,
  647.                 !flipscreen,!flipscreen,
  648.                 sx,sy,
  649.                 flipscreen ? &spritevisibleareaflip : &spritevisiblearea,TRANSPARENCY_COLOR,0);
  650.     }
  651.  
  652.  
  653.     /* draw the cars on the radar */
  654.     for (offs = 0; offs < rallyx_radarram_size;offs++)
  655.     {
  656.         int x,y;
  657.  
  658.         /* it looks like the addresses used are
  659.            a000-a003  a004-a00f
  660.            8020-8023  8034-803f
  661.            8820-8823  8834-883f
  662.            so 8024-8033 and 8824-8833 are not used
  663.         */
  664.  
  665.         x = rallyx_radarx[offs] + ((~rallyx_radarattr[offs & 0x0f] & 0x08) << 5);
  666.         if (flipscreen) x += 32;
  667.         y = 237 - rallyx_radary[offs];
  668.  
  669.         drawgfx(bitmap,Machine->gfx[2],
  670.                 (rallyx_radarattr[offs & 0x0f] & 0x07) ^ 0x07,
  671.                 0,
  672.                 flipscreen,flipscreen,
  673.                 x,y,
  674. //                &Machine->drv->visible_area,TRANSPARENCY_PEN,3);
  675.                 flipscreen ? &spritevisibleareaflip : &spritevisiblearea,TRANSPARENCY_PEN,3);
  676.     }
  677. }
  678.  
  679.  
  680.  
  681. void commsega_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  682. {
  683.     int offs,sx,sy;
  684.  
  685.  
  686.     /* for every character in the Video RAM, check if it has been modified */
  687.     /* since last time and update it accordingly. */
  688.     for (offs = videoram_size - 1;offs >= 0;offs--)
  689.     {
  690.         if (dirtybuffer2[offs])
  691.         {
  692.             int flipx,flipy;
  693.  
  694.  
  695.             dirtybuffer2[offs] = 0;
  696.  
  697.             sx = offs % 32;
  698.             sy = offs / 32;
  699.             /* not a mistake, one bit selects both  flips */
  700.             flipx = rallyx_colorram2[offs] & 0x80;
  701.             flipy = rallyx_colorram2[offs] & 0x80;
  702.             if (flipscreen)
  703.             {
  704.                 sx = 31 - sx;
  705.                 sy = 31 - sy;
  706.                 flipx = !flipx;
  707.                 flipy = !flipy;
  708.             }
  709.  
  710.             drawgfx(tmpbitmap1,Machine->gfx[0],
  711.                     (rallyx_videoram2[offs]&0x7f) + 2*(rallyx_colorram2[offs]&0x40) + 2*(rallyx_videoram2[offs]&0x80),
  712.                     rallyx_colorram2[offs] & 0x3f,
  713.                     flipx,flipy,
  714.                     8*sx,8*sy,
  715.                     0,TRANSPARENCY_NONE,0);
  716.         }
  717.     }
  718.  
  719.     /* update radar */
  720.     for (offs = videoram_size - 1;offs >= 0;offs--)
  721.     {
  722.         if (dirtybuffer[offs])
  723.         {
  724.             int flipx,flipy;
  725.  
  726.  
  727.             dirtybuffer[offs] = 0;
  728.  
  729.             sx = (offs % 32) ^ 4;
  730.             sy = offs / 32 - 2;
  731.             /* not a mistake, one bit selects both  flips */
  732.             flipx = colorram[offs] & 0x80;
  733.             flipy = colorram[offs] & 0x80;
  734.             if (flipscreen)
  735.             {
  736.                 sx = 7 - sx;
  737.                 sy = 27 - sy;
  738.                 flipx = !flipx;
  739.                 flipy = !flipy;
  740.             }
  741.  
  742.             drawgfx(tmpbitmap,Machine->gfx[0],
  743.                     (videoram[offs]&0x7f) + 2*(colorram[offs]&0x40) + 2*(videoram[offs]&0x80),
  744.                     colorram[offs] & 0x3f,
  745.                     flipx,flipy,
  746.                     8*sx,8*sy,
  747.                     &radarvisibleareaflip,TRANSPARENCY_NONE,0);
  748.         }
  749.     }
  750.  
  751.  
  752.     /* copy the temporary bitmap to the screen */
  753.     {
  754.         int scrollx,scrolly;
  755.  
  756.  
  757.         if (flipscreen)
  758.         {
  759.             scrollx = (*rallyx_scrollx) + 32;
  760.             scrolly = (*rallyx_scrolly + 16) - 32;
  761.         }
  762.         else
  763.         {
  764.             scrollx = -(*rallyx_scrollx);
  765.             scrolly = -(*rallyx_scrolly + 16);
  766.         }
  767.  
  768.         copyscrollbitmap(bitmap,tmpbitmap1,1,&scrollx,1,&scrolly,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  769.     }
  770.  
  771.  
  772.     /* radar */
  773.     if (flipscreen)
  774.         copybitmap(bitmap,tmpbitmap,0,0,0,0,&radarvisibleareaflip,TRANSPARENCY_NONE,0);
  775.     else
  776.         copybitmap(bitmap,tmpbitmap,0,0,28*8,0,&radarvisiblearea,TRANSPARENCY_NONE,0);
  777.  
  778.  
  779.     /* draw the sprites */
  780.     for (offs = 0;offs < spriteram_size;offs += 2)
  781.     {
  782.         int flipx,flipy;
  783.  
  784.  
  785.         sx = spriteram[offs + 1] - 1;
  786.         sy = 224 - spriteram_2[offs];
  787. if (flipscreen) sx += 32;
  788.         flipx = ~spriteram[offs] & 1;
  789.         flipy = ~spriteram[offs] & 2;
  790.         if (flipscreen)
  791.         {
  792.             flipx = !flipx;
  793.             flipy = !flipy;
  794.         }
  795.  
  796.         if (spriteram[offs] & 0x01)    /* ??? */
  797.             drawgfx(bitmap,Machine->gfx[1],
  798.                     ((spriteram[offs] & 0x7c) >> 2) + 0x20*(spriteram[offs] & 0x01) + ((spriteram[offs] & 0x80) >> 1),
  799.                     spriteram_2[offs + 1] & 0x3f,
  800.                     flipx,flipy,
  801.                     sx,sy,
  802.                     &Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  803.     }
  804.  
  805.  
  806.     /* draw the cars on the radar */
  807.     for (offs = 0; offs < rallyx_radarram_size;offs++)
  808.     {
  809.         int x,y;
  810.  
  811.  
  812.         /* it looks like the addresses used are
  813.            a000-a003  a004-a00f
  814.            8020-8023  8034-803f
  815.            8820-8823  8834-883f
  816.            so 8024-8033 and 8824-8833 are not used
  817.         */
  818.  
  819.         x = rallyx_radarx[offs] + ((~rallyx_radarattr[offs & 0x0f] & 0x08) << 5);
  820.         if (flipscreen) x += 32;
  821.         y = 237 - rallyx_radary[offs];
  822.  
  823.  
  824.         drawgfx(bitmap,Machine->gfx[2],
  825.                 (rallyx_radarattr[offs & 0x0f] & 0x07) ^ 0x07,
  826.                 0,
  827.                 flipscreen,flipscreen,
  828.                 x,y,
  829.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,3);
  830.     }
  831. }
  832.